using KinonekoSoftware.CodariaDB.Documents.Theories.Chikara;

namespace KinonekoSoftware.Studio.Pages.Theories
{
    partial class WorldViewConfigTheoryViewModel
    {
        
        //-------------------------------------------------
        //
        //          Command Handlers
        //
        //-------------------------------------------------

        private async void DoNewChikaraCommand()
        {
            var r = await NewChikaraViewModel.Create();

            if (!r.IsFinished)
            {
                return;
            }

            var val = r.Value;

            //
            //
            _theory_chikara.Add(val);

            //
            //
            Chikara.Add(val);

            //
            //
            Save();
        }

        private async void DoEditChikaraCommand(Chikara element)
        {

            if (element is null)
            {
                return;
            }

            var r = await NewChikaraViewModel.Edit(element);

            if (!r.IsFinished)
            {
                return;
            }

            //
            //
            _theory_chikara.Update(r.Value);

            //
            //
            Save();

        }

        private async void DoResetChikaraCommand()
        {
            if (!await DangerOperation(TitleSR.DangerOperation, TextSR.Remove_Item_All))
            {
                return;
            }
            
            
            
            Chikara.Clear();
            _theory_chikara.Clear();
            
            //
            Save();
        }

        private async void DoRemoveChikaraCommand(Chikara element)
        {
            if (element is null)
            {
                return;
            }

            if (!await RemoveItem())
            {
                return;
            }

            Chikara.Remove(element);
            _theory_chikara.Remove(element);

            Save();
        }



        //-------------------------------------------------
        //
        //          Properties
        //
        //-------------------------------------------------
        public ICommandEX NewChikaraCommand    { get; }
        public ICommandEX EditChikaraCommand   { get; }
        public ICommandEX ResetChikaraCommand  { get; }
        public ICommandEX RemoveChikaraCommand { get; }

        public ObservableCollection<Chikara> Chikara { get; }
    }
}